package Exercise;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class DateBirthdayTest {

    public static void main(String[] args) throws ParseException {
        Date date = new Date();


        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个yyyy-MM-DD格式的出生日期来让计算机来计算你活了多少天");
        while (true) {
            String res = scanner.next();


            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-DD");
            Date birthday = simpleDateFormat.parse(res);
            long num = ((date.getTime() - birthday.getTime()) / 1000 / 60 / 60 / 24);
            if (date.getTime() > birthday.getTime()) {

                System.out.println("你距" + res + "已经过了" + num + "个日日夜夜");
                System.exit(0);
            } else {
                System.out.println("你输入的时间不准确,请重新输入");
            }
        }
    }
}
